package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_01_附加效果;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 固守（每经过X回合，为目标附加另外一个buff)
 * @date 2022/2/25 12:04
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.固守)
public class Affix73DefendTenaciously extends Buff {
    public Affix73DefendTenaciously(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getRoundPer() {return getParam(0);}
    private int getBuffID() {return getParam(1);}

    private RecordStreamGroup steamGroup;

    @Override
    public RecordStreamGroup record() {
        steamGroup = getRecord().stream(new RecordStreamGroup());
        steamGroup.add(new RecordStream_SKL(getActor(), getBuffID()));
        return steamGroup;
    }

    @Override
    public boolean exec(Fighter source, Fighter target) {
        int nowRound = source.getContext().getRound();
        if(nowRound % getRoundPer() == 0){
            skill skilldata = DataCenter.getData(getBuffID(), skill.class);
            Buff buff = AffixFactory.getInstance().getBuff(AffixFactory.BuffTypeEnum.valueOf(skilldata.getBufftype()), source, target, skilldata, getSelfParams(skilldata));
            buff.append(target);

            // 流脚本
            RecordStream_01_附加效果 recordSteam = steamGroup.add(new RecordStream_01_附加效果(target));
            recordSteam.addBuff(buff);

            recordSteam.record();

            // 输出
            Battle.battleLogger(6,"固守："+source.getName()+" 对  " + target.getName() + " 附加BUFF:(" + this + ")[" + getSkilldata().getBuffid() + buff + "]"+"当前回合："+nowRound);
        }else{
            Battle.battleLogger(6,"固守：回合未到，未触发。当前回合："+nowRound);
        }

        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.defendTenaciouslyState;
    }

    private int[] getSelfParams(skill skilldata){
        int[] params = new int[skilldata.getParam().length];
        for (int i = 0; i < params.length; i++) {
            params[i] = skilldata.getParam()[i];
        }
        return params;
    }

}
